package test.temple;

import java.util.List;
import java.util.Map;

import com.weight.common.generate.base.ResourceFile;


/**
* 
*  
*/
public class queryHtmlResourceFile extends ResourceFile {
	private static final String FILE_NAME = ".html";
	
	public queryHtmlResourceFile(String filePath,String packageName,String model,List<String> fieldENList,List<String> fieldCNList,String tableCnName) {
		
		super(filePath,new StringBuilder("queryFor").append(getModelClass(model)).append("List").append(FILE_NAME).toString());
//常量		
		StringBuilder urlPath=new StringBuilder().append(packageName).append("/").append(model).append("/");//url路径
		StringBuilder beanName=getModelClass(model);//对象
		
		StringBuilder  resourceFile =new StringBuilder();
		
		resourceFile.append("<div style=\"padding:10px 20px 20px 20px;margin:0px 0;\">\n");
//查询条件	
		resourceFile.append("\t<div style=\"float:left;margin:10px 0px 10px 0;width:100%;\">\n");
		resourceFile.append("\t<form th:id=\"${formID}\" action=\"#\"  method=\"post\" enctype=\"multipart/form-data\">\n");
		for(int i=1;i<fieldENList.size();i++) {
//			if(i==0) {
//				resourceFile.append("\t\t<div style=\"float:left;\">\n");
//			}else {
				resourceFile.append("\t\t<div style=\"margin:0 20px;float:left;\">\n");
//			}
			resourceFile.append("\t\t<input  id=\"").append(fieldENList.get(i)).append("\" class=\"easyui-textbox wd50\" type=\"text\" ")					 
						.append("\n\t\t\t\t\tth:label=\"#{").append(model).append(".").append(fieldENList.get(i))
						.append("}+'  :'\" label=\"").append(fieldCNList.get(i))
						.append("\"  name=\"").append(fieldENList.get(i)).append("\"   />\n");
			resourceFile.append("\t\t\t<br style=\"clear:both;\">\n");
			resourceFile.append("\t\t</div>\n");
		}
		//查询按钮
		resourceFile.append("\t\t<div style=\"margin:0 20px;float:left;clear:right;\">\n");
		resourceFile.append("\t\t\t<a th:href=\"'javascript:search(\\''+${formID}+'\\')'\" class=\"easyui-linkbutton\" iconCls=\"icon-search\">查询</a>\n");
		resourceFile.append("\t\t</div>\n");
		
		resourceFile.append("\t</form>\n");
		resourceFile.append("\t</div>\n");
		         
//批量，导入，导出
		//批量
		resourceFile.append("\t<div style=\"float:left;margin-bottom:1px;width:100%;\">\n");
		resourceFile.append("\t<div style=\"float:left;\">\n");
		//关联URL
		resourceFile.append("\t\t<a th:href=\"'javascript:batchdel(\\''+${formID}+'\\')'\" class=\"easyui-linkbutton\">批量删除</a>\n");
		resourceFile.append("\t\t<input th:id=\"'show'+${formID}\" type=\"hidden\" th:value=\"@{").append(urlPath)
					.append("queryFor").append(beanName).append("Detail}\" />\n");
		resourceFile.append("\t\t<input th:id=\"'edit'+${formID}\" type=\"hidden\" th:value=\"@{").append(urlPath)
					.append("add").append(beanName).append("}\" /> \n");
		resourceFile.append("\t\t<input th:id=\"'del'+${formID}\" type=\"hidden\" th:value=\"@{").append(urlPath)
					.append("deleteBy").append(beanName).append("Id}\" />\n");
		resourceFile.append("\t\t<input th:id=\"'mid'+${formID}\" type=\"hidden\" value=\"").append(fieldENList.get(0)).append( "\" />\n");
		resourceFile.append("\t\t<input th:id=\"'batchdel'+${formID}\" type=\"hidden\" th:value=\"@{").append(urlPath)
					.append("deleteBy").append(beanName).append("IdBatch}\" /> \n");
		resourceFile.append("\t</div>\n");
//导入，导出
		resourceFile.append("\t<div style=\"margin-left:10px;float:right;\">\n");
		resourceFile.append("\t\t<a th:id=\"'imp'+${formID}\"  href=\"#\" class=\"easyui-linkbutton\" iconCls=\"\" th:onclick=\"'javascript:importExcelMode(\\''+${formID}+'\\')'\">导入</a>&nbsp;\n");
		resourceFile.append("\t\t<a href=\"#\" class=\"easyui-linkbutton\" iconCls=\"\" th:onclick=\"'javascript:downloadExcelMode(\\''+@{/UploadFiles/Fj/AqglHseAqjc.xlsx}+'\\')'\">下载模板</a> &nbsp;\n");
		resourceFile.append("\t\t<a href=\"#\" class=\"easyui-linkbutton\" iconCls=\"\" onclick=\"exportExcelMode(\\''+${formID}+'\\')'\">导出</a>\n");
		resourceFile.append("\t\t\n");
		resourceFile.append("\t</div>\n");
		resourceFile.append("\t<form th:id=\"'impForm'+${formID}\" action=\"#\"  method=\"post\" enctype=\"multipart/form-data\"> \n");
		resourceFile.append("\t\t<div style=\"margin-left:10px;float:right;\">\n");
		resourceFile.append("\t\t\t<input class=\"easyui-filebox\"\n");
		resourceFile.append("\t\t\tdata-options=\"label:'导入文件:',prompt:'请选择一个Excel文件',buttonText:'选择文件',\n");
		resourceFile.append("\t\t\taccept:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel'\"\n");
		resourceFile.append("\t\t\tth:id=\"'file'+${formID}\"  name=\"file\" style=\"width:300px;\">\n");
		resourceFile.append("\t\t</div>\n");
		resourceFile.append("\t</form>\n");
		resourceFile.append("\t</div>\n");
		
		
		resourceFile.append("\n");     
//展示列表		
		resourceFile.append("\t<table  th:id=\"'datagrid'+${formID}\" class=\"easyui-datagrid\" title=\"").append(tableCnName).append("\" style=\"width:100%;\"\n");
		resourceFile.append("\t\t\tdata-options=\"url:'").append(urlPath).append("queryFor").append(beanName).append("ListDG',\n");
		resourceFile.append( "\t\t\tmethod:'get',rownumbers:true, nowrap: false,singleSelect:false,autoRowHeight: true,\n");
		resourceFile.append( "\t\t\tfitColumns: true,striped:true,idField:'menuInfoId',loadMsg: '正在加载...',pagination:true,pageSize:10\">\n");
		
		resourceFile.append("\t\t<thead data-options=\"frozen:true\">\n");
		resourceFile.append("\t\t\t<tr>\n");
		resourceFile.append("\t\t\t\t<th data-options=\"field:'ck',checkbox:true\" ></th>\n");
//		resourceFile.append("\t\t\t</tr>\n");
//		resourceFile.append("\t\t</thead>\n");
//		resourceFile.append("\t\t<thead>\n");
//		resourceFile.append("\t\t\t<tr>\n");
		
		for(int i=1;i<fieldENList.size();i++) {
			resourceFile.append("\t\t\t\t<th data-options=\"field:'").append(fieldENList.get(i))
						.append("',resizable:true,halign:'center'\" width=\"15%\"><span th:text=\"#{").append(model).append(".")
						.append(fieldENList.get(i)).append("}\">").append(fieldCNList.get(i)).append("</span></th>\n"); 
		}
		 
		resourceFile.append("\t\t\t</tr>\n");
		resourceFile.append("\t\t</thead>\n");
		resourceFile.append("\t</table> \n");
		resourceFile.append("</div> \n");
		
//javascript
		resourceFile.append("<script type=\"text/javascript\">\n");
		
		resourceFile.append("\t//操作\n");
		resourceFile.append("\tfunction onOpt").append(beanName).append("(value,row,index){ \n");
		resourceFile.append("\t\tvar s =  '<a class=\"Edit_Button\" href=\"javascript:showDetail(\\''+value+'\\',\\'展示《'+row.")
					.append(fieldENList.get(1)).append("+'》详情信息\\',\\'[[${formID}]] \\')\">详细</a>'+\n");
		
		resourceFile.append("\t\t\t'&nbsp;'+\n");
		resourceFile.append("\t\t\t'<a class=\"Edit_Button\" href=\"javascript:edit(\\''+value+'\\',\\'编辑《'+row.")
					.append(fieldENList.get(1)).append("+'》信息\\',\\'[[${formID}]] \\')\">编辑</a>'+\n");
		resourceFile.append("\t\t\t'&nbsp;'+\n");
		resourceFile.append("\t\t\t'<a class=\"Delete_Button\" href=\"javascript:remove(\\''+value+'\\',\\'[[${formID}]]\\')\" >删除</a>' ;\n");
		resourceFile.append("\t\treturn s;\n");
		
		resourceFile.append("\t}\n");
		resourceFile.append("\t\n");
		
		
		resourceFile.append("\t//导入 \n");
		resourceFile.append("\tfunction importExcelMode(formID){\n");
		resourceFile.append("\t\tvar file = $('#file'+formID).filebox('getValue');\n");
		resourceFile.append("\t\tif(file==\"\"){ \n");
		resourceFile.append("\t\t\t $.messager.alert({ width: 350, title:'温馨提示', msg:'导入文件不能为空!', icon:'info'});\n");
		resourceFile.append("\t\t\treturn; \n");
		resourceFile.append("\t\t}\n");
		
		resourceFile.append("\t\t $('#imp'+formID).linkbutton('disable');\n");
		resourceFile.append("\t\t$(\"#impForm\"+formID).ajaxSubmit({\n");
		
		resourceFile.append("\t\t\ttype: \"post\",\n");
		resourceFile.append("\t\t\tdataType: \"json\",\n");
		resourceFile.append("\t\t\turl: '[[@{").append(urlPath).append("importGenerateInfo }]]', \n");
		resourceFile.append("\t\t\tsuccess:function(data){ \n");
		resourceFile.append("\t\t\t\t$('#imp'+formID).linkbutton('enable'); \n");
		resourceFile.append("\t\t\t\tconsole.log(data)\n");
		resourceFile.append("\t\t\t\tif (data.code == 200) {\n");
		resourceFile.append("\t\t\t\t\tdataReload(formID); \n");
		resourceFile.append("\t\t\t\t\t$.messager.alert({width: 280,title: '操作成功',msg: data.msg, icon:'info'});\n");
		resourceFile.append("\t\t\t\t}else{\n");
		resourceFile.append("\t\t\t\t\t$.messager.alert({ width: 280, title:'数据提交异常', msg:data.msg});\n");
		resourceFile.append("\t\t\t\t}\n");
		resourceFile.append("\t\t\t},error: function (data) {\n");
		resourceFile.append("\t\t\t\t$('#imp'+formID).linkbutton('enable'); \n");
		resourceFile.append("\t\t\t\t$.messager.alert('消息提醒','上传失败，数据异常！');\n");
		resourceFile.append("\t\t\t}\n");
		resourceFile.append("\t\t});\n");
		resourceFile.append("\t}\n");
		
		
		resourceFile.append("\t\t\t\n");
		resourceFile.append("\t\t\t\n");
		
		resourceFile.append("\t\t\n");
		resourceFile.append("\t\n");
	               
		
		
		
		
		
		
		resourceFile.append("\n");    
		resourceFile.append("</script>\n");
		resourceFile.append("\n");       
		resourceFile.append("\n");
		       
	            
		resourceFile.append("\n");
		
		for(int i=1;i<fieldENList.size();i++) {
			resourceFile.append("\t\t\t\t<th class=\"text-center\"> ") .append(fieldCNList.get(i)).append("</th>\n"); 
		}
		
		resourceFile.append("<tr th:each=\"").append(model).append(" : ${").append(model).append("VOList}\">\n" + 
		"					    <td><input type=\"checkbox\" name=\"interest\" th:value=\"${").append(model).append(".").append(fieldENList.get(0)).append("}\"/></td>\n" + 
		"						<td><span th:text=\"${").append(model).append("Stat.count}\"></span></td>");
		for(int i=1;i<fieldENList.size();i++) {
			resourceFile.append("\t\t\t\t<td><span th:text=\"${").append(model).append(".")
						.append(fieldENList.get(i)).append("}\">").append("</span></td>\n"); 
		}
		
		String resource = resourceFile.toString();
		init(resource);
	}
}
